<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends CI_Controller {

	public function Main()
	{
		parent::__construct();
	}
	
        public function addInfo(){
            $this->load->model('Automatmodel');
            $this->Automatmodel->setInfo(1,"First automate. Here will be some text.");
            $this->Automatmodel->setInfo(2,"Second automate. Here will be some text.");
            $this->Automatmodel->setInfo(3,"123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567890123456789 1234567890");
        }
        
        public function testCanSell(){
            $this->load->model('Waremodel');
            $res = $this->Waremodel->setCanSell(7,false);
        }
        
	public function index()
	{
		echo 'Test controller!<p>----------------------------------------------------</p>';
		echo '<p>Usermodel->getAllUsers();</p>';
		$this->load->model('Usermodel');
		$this->Usermodel->addUser('user','trololol');
                $id= $this->Usermodel->getUserIdByLogin('user');
                echo 'USERID:'.$id;
                $this->Usermodel->setUserData($id,"megapihar2000@mail.ru","Vadik","0972436574");
                $this->Usermodel->setIsActivated($id,true);
                $this->Usermodel->setDeleteRequest($id,true);
		//$this->Usermodel->deleteUser(2);
		//$this->Usermodel->changePass(1,'whosyourdaddy');
		/*
		if( $this->Usermodel->loginPassValid('admin','whosyourdaddy') ){
			echo 'user valid';
		}
		else{
			echo 'invalid user';
		}
		*/
		
		$query = $this->Usermodel->getAllUsers();
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'UsrId:';
			echo $row['UserId'];
			echo ' Login:';
			echo $row['Login'];
                        echo ' Email:';
			echo $row['Email'];
                        echo ' Name:';
			echo $row['Name'];
                        echo ' Telephone:';
			echo $row['TelNumber'];
                        echo ' IsActivated:';
			echo $row['IsActivated'];
                        echo ' DeleteRequest:';
			echo $row['DeleteRequest'];
			echo '</p>';
			$i++;
		}
		echo '<p>---getAllUsers : TestComplete---</p>';
		echo '<p>--- Automatmodel ---</p>';
/*		$this->load->model('Automatmodel');
		echo 'model loaded';
		echo '<p>addAutomat:</p>';
		$res = $this->Automatmodel->addAutomat("2011-10-26 00:42:00",48.922778, 24.710556,'192.168.1.100',1,1000000,true);
		$res = $this->Automatmodel->addAutomat("2011-10-26 00:42:00",48.922778, 24.710556,'192.168.1.100',1,1000000,true);
		echo '<p>getAllAutomats:</p>';
                $arg = 1;
		$query = $this->Automatmodel->getAllAutomates($arg);
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'AutomatId:';
			echo $row['AutomatId'];
			echo ' ConnectTime:';
			echo $row['ConnectTime'];
			echo ' Latitude:';
			echo $row['Latitude'];
			echo ' Longitude:';
			echo $row['Longitude'];
			echo ' IP:';
			echo $row['IP'];
			echo ' Balance:';
			echo $row['Balance'];
			echo ' Serviceability:';
			echo $row['Serviceability'];
			echo '</p>';
			$i++;
		}
		$automatId1 = $query[0]['AutomatId'];
		$automatId2 = $query[1]['AutomatId'];
		echo '<p>changing automat data</p>';
		$res = $this->Automatmodel->setConnectTime($query[0]['AutomatId'], "3011-10-26 00:42:00");
		$res = $this->Automatmodel->setPosition($query[0]['AutomatId'], 8.922778, 4.710556);
		$res = $this->Automatmodel->setIP($query[0]['AutomatId'], '192.168.1.101');
		$res = $this->Automatmodel->setBalance($query[0]['AutomatId'], 2000000);
		$res = $this->Automatmodel->setServiceability($query[0]['AutomatId'], false);
		echo '<p>getAllAutomats:</p>';
		$query = $this->Automatmodel->getAllAutomates(1);
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'AutomatId:';
			echo $row['AutomatId'];
			echo ' ConnectTime:';
			echo $row['ConnectTime'];
			echo ' Latitude:';
			echo $row['Latitude'];
			echo ' Longitude:';
			echo $row['Longitude'];
			echo ' IP:';
			echo $row['IP'];
			echo ' Balance:';
			echo $row['Balance'];
			echo ' Serviceability:';
			echo $row['Serviceability'];
			echo '</p>';
			$i++;
		}
		
		echo '<p>--- Testing of Automatmodel complited ---</p>';
		
*/		
/*		echo '<p>--- Productmodel ---</p>';
		$this->load->model('Productmodel');
		echo 'model loaded';
		echo '<p>addProduct:</p>';
		$res = $this->Productmodel->addProduct(101010,'English book',"English is better because i don\'t have to f*** with encoding.");
		$res = $this->Productmodel->addProduct(101312,'Ware name 2','any product you want');
		echo '<p>getAllProducts:</p>';
		$query = $this->Productmodel->getAllProducts();
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'ProductCode:';
			echo $row['ProductCode'];
			echo ' Name:';
			echo $row['Name'];
			echo ' ShortInfo:';
			echo $row['ShortInfo'];
			echo '</p>';
			$i++;
		}
		$productCode1 = $query[0]['ProductCode'];
		$productCode2 = $query[1]['ProductCode'];
		echo '<p>--- Testing of Productmodel complited ---</p>';
*/		
/*		echo '<p>--- Waremodel ---</p>';
		$this->load->model('Waremodel');
		echo 'model loaded';
		echo '<p>addWare:</p>';
		$res = $this->Waremodel->addWare(200,100,1,101010,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(200,100,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
                $res = $this->Waremodel->addWare(150,50,1,101312,true,'00:00:00','00:00:00');
		$res = $this->Waremodel->addWare(200,100,2,101312,true,'00:00:00','00:00:00');
		echo '<p>getAllWares:</p>';
		$query = $this->Waremodel->getAllWares();
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'WareId:';
			echo $row['WareId'];
			echo ' Price:';
			echo $row['Price'];
			echo ' Amount:';
			echo $row['Amount'];
			echo ' AutomatId:';
			echo $row['AutomatId'];
			echo ' ProductCode:';
			echo $row['ProductCode'];
			echo ' CanSell:';
			echo $row['CanSell'];
			echo ' SellFrom:';
			echo $row['SellFrom'];
			echo ' SellTo:';
			echo $row['SellTo'];
			echo '</p>';
			$i++;
		}
		echo '<p>updating ware</p>';
		$res = $this->Waremodel->updateWare($query[0]['WareId'],210,200,$automatId2,101010,null,'22:00:00');
		$res = $this->Waremodel->setCanSell($query[0]['WareId'],false);
		
		echo '<p>getAllWares:</p>';
		$query = $this->Waremodel->getAllWares();
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'WareId:';
			echo $row['WareId'];
			echo ' Price:';
			echo $row['Price'];
			echo ' Amount:';
			echo $row['Amount'];
			echo ' AutomatId:';
			echo $row['AutomatId'];
			echo ' ProductCode:';
			echo $row['ProductCode'];
			echo ' CanSell:';
			echo $row['CanSell'];
			echo ' SellFrom:';
			echo $row['SellFrom'];
			echo ' SellTo:';
			echo $row['SellTo'];
			echo '</p>';
			$i++;
		}
		$wareId1 = $query[0]['WareId'];
		$wareId2 = $query[1]['WareId'];
		
		echo '<p>--- Testing of Waremodel complited ---</p>';
		
		echo 'CLEANUP:';
 
 */
//		echo '<p>deleting wares</p>';
//		$res = $this->Waremodel->deleteWare($wareId1);
//		$res = $this->Waremodel->deleteWare($wareId2);
//		echo '<p>deleting products</p>';
//		$res = $this->Productmodel->deleteProduct($productCode1);
//		$res = $this->Productmodel->deleteProduct($productCode2);
//		echo '<p>deleting automats</p>';
		//$res = $this->Automatmodel->deleteAutomat($automatId1);
		//$res = $this->Automatmodel->deleteAutomat($automatId2);
	/*	
		echo '<p>--- Logmodel ---</p>';
		$this->load->model('Logmodel');
		$this->Logmodel->log(1,1);
		$this->Logmodel->log(2,2);
		$query = $this->Logmodel->getLog();
		$i = 0;
		$numOfRows = count($query);
		while($i < $numOfRows){
			$row = $query[$i];
			echo '<p>';
			echo 'LogId:';
			echo $row['LogId'];
			echo ' WareId:';
			echo $row['WareId'];
			echo ' AutomatId:';
			echo $row['AutomatId'];
			echo ' DateTime:';
			echo $row['DateTime'];
			echo '</p>';
			$i++;
		}
		echo '<p>--- Logmodel testing complited ---</p>';
         
         */
	}
}